import javax.swing.*;

/**
 * Created by IntelliJ IDEA.
 * User: kristoffer
 * Date: 3/23/12
 * Time: 9:40 AM
 * To change this template use File | Settings | File Templates.
 */
public class RelationListModel extends AbstractListModel<Relation> {

    private Relations relations;

    public RelationListModel(Relations relations) {
        this.relations = relations;
    }

    public void setRelations(Relations relations) {
        this.relations = relations;
    }

    @Override
    public int getSize() {
        if (relations == null) {
            return 0;
        }
        return relations.size();
    }

    @Override
    public Relation getElementAt(int i) {
        if (i >= relations.size()) {
            return null;
        }

        return relations.get(i);
    }

    public void update() {
        fireContentsChanged(this, 0, getSize());
    }
}
